package org.fin.minicat.responce;

import org.fin.minicat.protocol.HttpStatusCode;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;

public class Responce {

  private HttpResponceHeader httpResponceHeader;

  private byte[] content;

  public void setStatusCode(HttpStatusCode statusCode) {
    Objects.requireNonNull(httpResponceHeader, "设置status code之前必须设置http header");
    httpResponceHeader.setStatusCode(statusCode);
  }

  public HttpResponceHeader getHttpResponceHeader() {
    return httpResponceHeader;
  }

  public void setHttpResponceHeader(HttpResponceHeader httpResponceHeader) {
    this.httpResponceHeader = httpResponceHeader;
  }

  public byte[] getContent() {
    return content;
  }

  public void setContent(byte[] content) {
    Objects.requireNonNull(httpResponceHeader, "设置content之前必须设置http header");
    int contentLength = content == null ? 0 : content.length;
    httpResponceHeader.setContentLength(contentLength);
    this.content = content;
  }

}
